package main

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"time"
)

var ctx = context.Background()

/*
Expire(),ExpireAt():设置有效期
需要在设置好了缓存项后，在设置有效期
*/
func main() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "81.68.186.20:6379",
		Password: "ffdd2021@",
		DB:       0,
	})
	defer rdb.Close()
	b, err := rdb.Expire(ctx, "name1", 1*time.Minute).Result()
	if err != nil {
		panic(err)
	}
	if b {
		fmt.Println("成功")
	} else {
		fmt.Println("失败")
	}

}
